<?php

declare(strict_types=1);
/**
 * This file is part of habo_new_media.
 *
 * @link     https://www.berlen.cn/
 * @contact  tech@berlen.cn
 * @license  http://gitlab.rehou.cn/habo/habo_new_media/-/blob/master/README.md
 */
namespace app\command;

use app\enum\CodeEnum;
use think\console\Command;

class BaseWork extends Command
{
    /**
     * @var array 错误消息
     */
    protected static array $error = [];

    /**
     * 获取错误消息.
     *
     * @param null|mixed $num 消息记录值
     * @return array|mixed|string
     */
    public static function getError($num = null)
    {
        if (is_null($num)) {
            return self::$error;
        }
        return self::$error[intval($num)] ?? CodeEnum::CODE_MESSAGE[CodeEnum::ERROR];
    }

    /**
     * 设置错误消息.
     *
     * @param string $msg 消息内容
     * @return false
     */
    protected static function setError(string $msg = ''): bool
    {
        self::$error[] = $msg;
        return false;
    }

    /**
     * 过滤已删除账户.
     */
    protected static function filterAccount(string $account = ''): bool
    {
        if (strpos($account, 'del')) {
            return false;
        }
        return true;
    }

    /**
     * 格式化输出消息.
     *
     * @param string $message 消息内容
     */
    protected function getOutputMessage(string $message = '')
    {
        $this->output->writeln('=======[' . date('Y-m-d H:i:s', time()) . '] ' . $message . '=======');
    }
}
